#include <stdio.h>

void swap(double *i, double *j)
{
  double temp;

  temp = *i;
  *i = *j;
  *j = temp;
}

int partition(double *a, int p, int r)
{
  int i, j;
  double key = a[r];
  for (i = p - 1, j = p; j < r; j++)
    if (a[j] <= key) {
      i++;
      swap((a + j), (a + i));
    }
  i++;
  swap((a + r), (a + i));
  return i;
}

void quick_sort(double *a, int p, int r)
{
  int q;

  if (p < r) {
    q = partition(a, p, r);
    quick_sort(a, p, q - 1);
    quick_sort(a, q + 1, r);
  }
}


